package com.qg.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.qg.pojo.QgUser;
import com.qg.service.LocalQgUserService;
import com.qg.service.QgUserService;
import com.qg.utils.Constants;
import com.qg.utils.EmptyUtils;
import com.qg.utils.RedisUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class LocalQgUserServiceImpl implements LocalQgUserService {

    @Reference
   private QgUserService qgUserService;

    @Resource
    private RedisUtil redisUtil;

    @Override
    public QgUser logUser(String phone, String password) throws Exception {
        QgUser qgUser=qgUserService.queryQgUserByPhoneAndPwd(phone,password);

        if(EmptyUtils.isEmpty(qgUser)){
            return null;
        }
         String userJSON=JSON.toJSONString(qgUser);
        redisUtil.setStr(Constants.token+qgUser.getId(),userJSON, Constants.timeOut);

        return qgUser;
    }
}
